package com.gc.base;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import tk.mybatis.mapper.common.Mapper;

import com.github.pagehelper.PageHelper;

public abstract class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    protected Mapper<T> mapper;

    public int save(T entity){
        return mapper.insert(entity);
    }

    public int delete(Serializable id){
        return mapper.deleteByPrimaryKey(id);
    }
    
    @Override
    public int update(T t) {
    	return mapper.updateByPrimaryKeySelective(t);
    }

    /**
     * 单表分页查询
     * 111
     * @param pageNum
     * @param pageSize
     * @return
     */
    public List<T> selectPage(int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return mapper.select(null);
    }
    
    @Override
    public List<T> selectAll() {
    	return mapper.selectAll();
    }
    
    @Override
    public List<T> selectByParams(T t) {
    	return mapper.select(t);
    }
    
    @Override
    public T selectOne(Serializable id) {
    	return mapper.selectByPrimaryKey(id);
    }
}